package cn.wsalix.finance.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.anlaser.service.impl.SimpleServiceImpl;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;
import cn.wsalix.finance.entity.Customer;
import cn.wsalix.finance.form.CustomerForm;
import cn.wsalix.finance.repository.CustomerRepository;
import cn.wsalix.finance.service.CustomerService;

@Service("customerService")
public class CustomerServiceImpl extends
		SimpleServiceImpl<CustomerForm, CustomerRepository, Customer> implements
		CustomerService {
	@Autowired
	private CustomerRepository customerRepository;

	@Override
	public String module() {
		return "/finance/customer";
	}

	@Override
	public CustomerRepository getRepository() {
		return customerRepository;
	}

	@Override
	public Class<Customer> getEntityClazz() {
		return Customer.class;
	}

	@Override
	public Map<String, SearchFilter> buildByForm(CustomerForm form) {
		Map<String, Object> searchParams = new HashMap<String, Object>();
		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);

		if (form.getName() != null && !form.getName().equals("")) {
			filters.put("name",
					new SearchFilter("nama", Operator.EQ, form.getName()));
		}
		return filters;
	}


}
